package com.topera.orderservice.service.impl;

import com.topera.commonutils.orderVo.CourseWebVoOrder;
import com.topera.commonutils.orderVo.UcenterMemberOrder;
import com.topera.orderservice.client.EduClient;
import com.topera.orderservice.client.UcenterClient;
import com.topera.orderservice.entity.Order;
import com.topera.orderservice.mapper.OrderMapper;
import com.topera.orderservice.service.OrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.topera.orderservice.utils.OrderNoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author puzhenjiang
 * @since 2020-06-12
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Autowired
    private EduClient eduClient;//远程调用使用
    @Autowired
    private UcenterClient ucenterClient;//远程调用使用

    @Override
    public String createOrder(String courseId, String memberId) {
        //1、课程信息
        CourseWebVoOrder courseInfoOrder = eduClient.getCourseInfoOrder(courseId);

        //2、用户信息
        UcenterMemberOrder userInforOrder = ucenterClient.getUserInforOrder(memberId);

        Order order = new Order();
        order.setOrderNo(OrderNoUtil.getOrderNo());//订单号
        order.setCourseCover(courseInfoOrder.getCover());//课程封面
        order.setCourseId(courseInfoOrder.getId());//课程id
        order.setCourseTitle(courseInfoOrder.getTitle());//课程标题
        order.setMemberId(userInforOrder.getId());//用户id
        order.setMobile(userInforOrder.getMobile());//手机号
        order.setNickname(userInforOrder.getNickname());//用户昵称
        order.setTeacherName(courseInfoOrder.getTeacherName());//讲师名称
        order.setTotalFee(courseInfoOrder.getPrice());//价格
        order.setStatus(0);//支付状态 0-未支付  1-支付
        order.setPayType(1);//支付方式  1-微信  2-支付宝

        baseMapper.insert(order);
        return order.getOrderNo();
    }
}
